package com.luzhikun.jackson;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.luzhikun.jackson.entity.Privince;

/**
 * @Author Rookie Coder
 * @Description 测试jackSon
 * @Date
 **/
public class TestJson {
    public static void main(String[] args) {

        // 使用jackson 把java对象转为json格式的字符串
        Privince privince=new Privince();
        privince.setId(1);
        privince.setName("吴杰");
        privince.setJiancheng("吴");
        privince.setShenghui("南京");

        // 使用jackson 把p转为json
        ObjectMapper obj=new ObjectMapper();
        try {
            // writeValueAsString把参数的java对象转为json格式的字符串
            String json=obj.writeValueAsString(privince);
            System.out.println(json);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

    }
}
